import os  # 可用于处理系统文件

# 打开文件
# f = open('test1.txt', mode='r', encoding='utf-8')  # 打开的是相对路径
with open('../第九章  模块/test2.txt', mode='r', encoding='utf-8') as f:  # 用with打开文件,可以自动关闭
    content = f.readlines()
    for i in content:
        print(i.strip())
    # print(content)
path = os.getcwd()  # 获取该文件目录显得绝对路径
filename = path + '\\test1.txt'  # 拼接文件绝对路径
with open(filename, mode='r', encoding='utf-8') as file1:
    for i in file1:
        print(i.strip())
# 读取文件
# content = f.read()  # f.read()读取文本所有内容
# content = f.readline()  # 只读取一行数据
# for line in f:
#     print(line.strip())
# 关闭文件
# f.close()
if os.path.exists("test1.txt"):
    print("文件存在")
else:
    print('文件不存在！')
